<?php

namespace App\Http\Requests\finance;

use App\Http\ValidateResult;
use Illuminate\Support\Facades\Validator;

trait CompensationRequest
{
    public static function add_check(array $params): ValidateResult {
        $validator = Validator::make($params, [
            'agent_id' => 'required|integer',
            'currency_id' => 'required|integer',
            'amount' => 'required|numeric',
            'pod_file' => 'required',
            'letter_file' => 'required',
            'invoice_file' => 'required',
            'list_file' => 'required',
//            'pic_file' => 'required',
        ], [
            'agent_id.required' => '请选择代理商',
            'currency_id.required' => '请选择币种',
            'amount.required' => '请填写金额',
            'pod_file.required' => '请上传POD文件',
            'letter_file.required' => '请上传索赔信',
            'invoice_file.required' => '请上传发票',
            'list_file.required' => '请上传箱单',
//            'pic_file.required' => '请上传图片附件'
        ]);

        if ($validator->fails()) {
            return ValidateResult::error($validator->errors()->first());
        }
        return ValidateResult::correct();
    }


    public static function admin_add_check(array $params): ValidateResult {
        $validator = Validator::make($params, [
            'take_order_sn' => 'required',
            'agent_id' => 'required|integer',
            'currency_id' => 'required|integer',
            'amount' => 'required|numeric',
            'pod_file' => 'required',
            'letter_file' => 'required',
            'invoice_file' => 'required',
            'list_file' => 'required',
//            'pic_file' => 'required',
        ], [
            'take_order_sn.required' => '请输入提单号',
            'agent_id.required' => '请选择代理商',
            'currency_id.required' => '请选择币种',
            'amount.required' => '请填写金额',
            'pod_file.required' => '请上传POD文件',
            'letter_file.required' => '请上传索赔信',
            'invoice_file.required' => '请上传发票',
            'list_file.required' => '请上传箱单',
//            'pic_file.required' => '请上传图片附件'
        ]);

        if ($validator->fails()) {
            return ValidateResult::error($validator->errors()->first());
        }
        return ValidateResult::correct();
    }

    public static function confirm_check(array $params): ValidateResult {
        $validator = Validator::make($params, [
            'actual_currency_id' => 'required|integer',
            'actual_amount' => 'required|numeric',
//            'compensate_remarks' => 'required',
        ], [
            'actual_currency_id.required' => '请选择币种',
            'actual_amount.required' => '请填写金额',
//            'compensate_remarks.required' => '请填写备注',
        ]);

        if ($validator->fails()) {
            return ValidateResult::error($validator->errors()->first());
        }
        return ValidateResult::correct();
    }


}
